package com.vf.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vf.common.annotation.Anonymous;
import com.vf.user.domain.DTO.GroupTypeDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vf.common.annotation.Log;
import com.vf.common.core.controller.BaseController;
import com.vf.common.core.domain.AjaxResult;
import com.vf.common.enums.BusinessType;
import com.vf.user.domain.GroupUser;
import com.vf.user.service.IGroupUserService;
import com.vf.common.utils.poi.ExcelUtil;
import com.vf.common.core.page.TableDataInfo;

/**
 * 用户加入分组Controller
 * 
 * @author LBS
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/user/groupUser")
public class GroupUserController extends BaseController
{
    @Autowired
    private IGroupUserService groupUserService;

    /**
     * 查询用户加入分组列表
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupUser groupUser)
    {
        startPage();
        List<GroupUser> list = groupUserService.selectGroupUserList(groupUser);
        return getDataTable(list);
    }

    /**
     * 导出用户加入分组列表
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:export')")
    @Log(title = "用户加入分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupUser groupUser)
    {
        List<GroupUser> list = groupUserService.selectGroupUserList(groupUser);
        ExcelUtil<GroupUser> util = new ExcelUtil<GroupUser>(GroupUser.class);
        util.exportExcel(response, list, "用户加入分组数据");
    }

    /**
     * 获取用户加入分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(groupUserService.selectGroupUserByGroupId(groupId));
    }

    /**
     * 新增用户加入分组
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:add')")
    @Log(title = "用户加入分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupUser groupUser)
    {
        return toAjax(groupUserService.insertGroupUser(groupUser));
    }

    /**
     * 修改用户加入分组
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:edit')")
    @Log(title = "用户加入分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupUser groupUser)
    {
        return toAjax(groupUserService.updateGroupUser(groupUser));
    }

    /**
     * 删除用户加入分组
     */
    @PreAuthorize("@ss.hasPermi('user:groupUser:remove')")
    @Log(title = "用户加入分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(groupUserService.deleteGroupUserByGroupIds(groupIds));
    }


    /**
     * 通过用户Id查询用户分组类型列表
     */
    @Anonymous
    @ApiOperation( value = "通过用户Id查询用户分组类型列表")
    @GetMapping("/groupListByUserId")
    public AjaxResult groupListByUserId( Long userId)
    {
//        Long userId = getUserId();
        return  success(groupUserService.groupListByUserId(userId));
    }
}
